<style>
    [data-level-zero] {
        top: 0;
        left: -10px;
        right: -10px;
        bottom: 3px;
        color: #FFF;
        display: flex;
        position: absolute;
        font-size: 18px;
        border-radius: 3px;
        align-items: center;
        justify-content: center;
        background: rgba(0, 0, 0, 0.4);
        text-shadow: #666 1px 1px 3px;
    }

    .min-input {
        width: 80px
    }

    .min-input[type=number] {
        padding-left: 15px
    }
</style>

<form action="{:sysuri()}" class="layui-form layui-card" data-auto="true" method="post">
    <div class="layui-card-body padding-left-40">

        <fieldset class="layui-form-item">
            <legend><span class="layui-badge layui-bg-cyan">用户等级</span></legend>
            <div class="layui-form-item layui-row layui-col-space15">
                <div class="layui-col-xs3 block relative">
                    <span class="help-label label-required-prev"><b>等级序号</b>Serial</span>
                    <select class="layui-select" name="number" lay-filter="number">
                        {for start="0" end="$max" name="i"}{if isset($vo.number) and $vo.number eq $i}
                        <option selected value="{$i}">当前 VIP {$vo.number} 等级</option>
                        {else}
                        <option value="{$i}">设置 VIP {$i} 等级</option>
                        {/if}{/for}
                    </select>
                </div>
                <label class="layui-col-xs9 block relative">
                    <span class="help-label label-required-prev"><b>等级名称</b>Name</span>
                    <input class="layui-input" name="name" placeholder="请输入等级名称" required value="{$vo.name|default=''}">
                </label>
            </div>
        </fieldset>

        <div class="layui-row layui-col-space15">
            <div class="layui-col-xs6">
                <fieldset class="layui-form-item">
                    <legend><span class="layui-badge layui-bg-cyan">升级规则</span></legend>
                    <div class="layui-form-item notselect">
                        {php}$vo['upgrade_type'] = $vo['upgrade_type'] ?? 1;{/php}
                        {foreach [1=>'达成所有升级条件',0=>'达成任何升级条件'] as $k => $v}
                        {if isset($vo.upgrade_type) and $vo.upgrade_type eq $k}
                        <label class="think-radio"><input checked lay-ignore name="upgrade_type" type="radio" value="{$k}"> {$v}</label>
                        {else}
                        <label class="think-radio"><input lay-ignore name="upgrade_type" type="radio" value="{$k}"> {$v}</label>
                        {/if}{/foreach}
                    </div>
                </fieldset>
            </div>
            <div class="layui-col-xs6">
                <fieldset class="layui-form-item">
                    <legend><span class="layui-badge layui-bg-cyan">团队计数</span></legend>
                    <div class="layui-form-item notselect">
                        {php}$vo['upgrade_team'] = $vo['upgrade_team'] ?? 1;{/php}
                        {foreach [1=>'参与团队人数统计',0=>'不参与团队人数统计'] as $k => $v}
                        {if isset($vo.upgrade_team) and $vo.upgrade_team eq $k}
                        <label class="think-radio"><input checked lay-ignore name="upgrade_team" type="radio" value="{$k}"> {$v}</label>
                        {else}
                        <label class="think-radio"><input lay-ignore name="upgrade_team" type="radio" value="{$k}"> {$v}</label>
                        {/if}{/foreach}
                    </div>
                </fieldset>
            </div>
        </div>

        <fieldset class="layui-form-item">
            <legend><span class="layui-badge layui-bg-cyan">升级条件</span></legend>
            <div class="font-s13 relative">
                <div>
                    <label class="think-checkbox notselect">
                        {if isset($vo.goods_vip_status) and $vo.goods_vip_status eq 1}
                        ① <input lay-ignore name="goods_vip_status" type="checkbox" value="1" checked>开启
                        {else}
                        ① <input lay-ignore name="goods_vip_status" type="checkbox" value="1">开启
                        {/if}
                        需要 <span class="color-blue">购买入会礼包</span> 达成升级；
                    </label>
                </div>
                <div>
                    <label class="think-checkbox notselect">
                        {if isset($vo.teams_direct_status) and $vo.teams_direct_status eq 1}
                        ② <input lay-ignore name="teams_direct_status" type="checkbox" value="1" checked>开启
                        {else}
                        ② <input lay-ignore name="teams_direct_status" type="checkbox" value="1">开启
                        {/if}
                        <span class="color-blue">直推团队</span> 升级，<span class="color-blue">直推团队</span> 达到
                        <input class="inline-block text-center min-input" name="teams_direct_number" data-blur-number="0" min="0" type="number" value="{$vo.teams_direct_number|default='0'}">
                        人；
                    </label>
                </div>
                <div>
                    <label class="think-checkbox notselect">
                        {if isset($vo.teams_indirect_status) and $vo.teams_indirect_status eq 1}
                        ③ <input lay-ignore name="teams_indirect_status" type="checkbox" value="1" checked>开启
                        {else}
                        ③ <input lay-ignore name="teams_indirect_status" type="checkbox" value="1">开启
                        {/if}
                        <span class="color-blue">间接团队</span> 升级，<span class="color-blue">间接团队</span> 达到
                        <input class="inline-block text-center min-input" name="teams_indirect_number" data-blur-number="0" min="0" type="number" value="{$vo.teams_indirect_number|default='0'}">
                        人；
                    </label>
                </div>
                <div>
                    <label class="think-checkbox notselect">
                        {if isset($vo.teams_users_status) and $vo.teams_users_status eq 1}
                        ④ <input lay-ignore name="teams_users_status" type="checkbox" value="1" checked>开启
                        {else}
                        ④ <input lay-ignore name="teams_users_status" type="checkbox" value="1">开启
                        {/if}
                        <span class="color-blue">团队总数</span> 升级，<span class="color-blue">团队总数</span> 达到
                        <input class="inline-block text-center min-input" name="teams_users_number" data-blur-number="0" min="0" type="number" value="{$vo.teams_users_number|default='0'}">
                        人；
                    </label>
                </div>
                <div>
                    <label class="think-checkbox notselect">
                        {if isset($vo.order_amount_status) and $vo.order_amount_status eq 1}
                        ⑤ <input lay-ignore name="order_amount_status" type="checkbox" value="1" checked>开启
                        {else}
                        ⑤ <input lay-ignore name="order_amount_status" type="checkbox" value="1">开启
                        {/if}
                        <span class="color-blue">订单总额</span> 升级，<span class="color-blue">订单总额</span> 达到
                        <input class="inline-block text-center min-input" name="order_amount_number" data-blur-number="2" min="0" type="number" value="{$vo.order_amount_number|default='0'}">
                        元；
                    </label>
                </div>
                <div data-level-zero class="layui-hide notselect">默认等级，无需配置升级规则</div>
            </div>
        </fieldset>

        <fieldset class="layui-form-item">
            <legend><span class="layui-badge layui-bg-cyan">奖利规则</span></legend>
            <div class="notselect relative">
                {foreach $prizes as $prize}{if isset($vo.rebate_rule) && is_array($vo.rebate_rule) && isset($vo.rebate_rule[$prize.code])}
                <label class="think-checkbox"><input lay-ignore name="rebate_rule[]" type="checkbox" value="{$prize.code}" checked> {$prize.name}</label>
                {else}
                <label class="think-checkbox"><input lay-ignore name="rebate_rule[]" type="checkbox" value="{$prize.code}"> {$prize.name}</label>
                {/if}{/foreach}
                <div data-level-zero class="layui-hide notselect">默认等级，不能发放等级奖励</div>
            </div>
        </fieldset>

        <fieldset class="layui-form-item layui-hide">
            <legend><span class="layui-badge layui-bg-cyan">等级描述</span></legend>
            <label class="layui-form-item block relative">
                <textarea class="layui-textarea" name="remark" placeholder="请输入用户等级描述">{$vo.remark|default=''}</textarea>
            </label>
        </fieldset>

    </div>

    <div class="hr-line-dashed"></div>
    {if isset($vo.id)}<input name='id' type='hidden' value='{$vo.id}'>{/if}
    {if isset($vo.number)}<input name='old_number' type='hidden' value='{$vo.number}'>{/if}

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" data-close data-confirm="确定要取消编辑吗？" type='button'>取消编辑</button>
    </div>

</form>

<script>
    $(function () {
        var $elem = $('[data-level-zero]');
        layui.form.on('select(number)', apply);
        apply({value: parseInt("{$vo.number|default=0}")});

        function apply(data) {
            data.value > 0 ? $elem.addClass('layui-hide') : $elem.removeClass('layui-hide');
        }
    });
</script>
